package com.sunseagear.common.utils;

import cn.hutool.json.JSONUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class JsonUtils extends JSONUtil{
    public static String toJsonString(Object obj) {
        return JSONUtil.toJsonPrettyStr(obj);
    }
    public static String toJsonStringInline(Object obj) {
        return JSONUtil.toJsonStr(obj);
    }

    public static <T> T toObject(String jsonString, Class<T> clazz) {
        return JSONUtil.toBean(jsonString, clazz);
    }

    public static <T> T[] toArray(String jsonString, Class<T[]> clazz) {
        return JSONUtil.parseArray(jsonString).toArray(clazz.cast(new Class[]{}));
    }

    public static <T> Map<String, T> toMap(String jsonString) {
        Map<String, T> map = new HashMap<>();
        JSONUtil.parseObj(jsonString).putAll(map);
        return map;
    }

    public static <T> List<T> toList(String jsonString, Class<T> clazz) {
        return JSONUtil.toList(jsonString, clazz);
    }

    public static Object getValue(String jsonString, String key) {
        return JSONUtil.parseObj(jsonString).get(key);
    }

}
